<?php
	require_once('./config.php');

	function TokenEncrypt($token)
	{
		global $security_string;

		$secret=$security_string;
		while(strlen($secret)<strlen($token))
			$secret .= $security_string;

		$token = base64_encode($token ^ $secret);

		return $token;
	}

	function TokenDecrypt($token)
	{
		global $security_string;

		$token = base64_decode($token);

		$secret=$security_string;
		while(strlen($secret)<strlen($token))
			$secret .= $security_string;

		$token = $token ^ $secret;

		return $token;
	}

	function GetToken()
	{
		$token=FALSE;

		if(isset($_GET['oauth_token']) && isset($_GET['oauth_token_secret']))
		{
			$token['oauth_token']=TokenDecrypt($_GET['oauth_token']);
			$token['oauth_token_secret']=TokenDecrypt($_GET['oauth_token_secret']);
		}
		else if(isset($_COOKIE['oauth_token']) && isset($_COOKIE['oauth_token_secret']))
		{
			$token['oauth_token']=TokenDecrypt($_COOKIE['oauth_token']);
			$token['oauth_token_secret']=TokenDecrypt($_COOKIE['oauth_token_secret']);
		}

		return $token;
	}
?>